import React, {useCallback} from 'react';
import {Button} from 'antd';
import {throttle} from 'lodash';
import {Props} from "@/components/ParamsTable/ParamsTable";

export type Props = {
  title: string;
  form: any;
  mLeft: number;
  // fastTestSpining: boolean;
  mBottom: number;
  submit: (values: API.InterfaceInfo) => Promise<void>;
};
const ParamsTable: React.FC<Props> = (props) => {
  const {title, submit, form, mLeft, mBottom} = props;
  const handleClick = useCallback(
    throttle(() => {
      // 处理按钮点击事件的逻辑
      if (form) {
        form?.submit(); // 调用表单的 submit 方法
        // console.log(' form Button clicked',form);
      } else {
        submit?.()
        // console.log(' submit Button clicked');
      }

    }, 1000), // 1000 毫秒的节流时间
    [form]
  );
  return (
    <Button type="primary" style={{marginLeft: mLeft, marginBottom: mBottom}}
            onClick={handleClick}>{title}</Button>
  );
};
export default ParamsTable;
